package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;

    @Override
    public List<Region> selectByParentId(Long parentId) {
        List<Region> list=regionMapper.selectByParentId(parentId);

        return list;
    }

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Region> list=regionMapper.selectByParentId(null);
        return new PageInfo(list);
    }

    @Override
    public List<Region> selectAll() {
        return regionMapper.selectAll();
    }

    @Override
    public void save(Region region) {
        if (region.getId() == null) {
            regionMapper.insert(region);
        }else{
            regionMapper.updateByPrimaryKey(region);
        }
    }

    @Override
    public List<Region> getListByState(Integer state) {
        List<Region>  regions= regionMapper.getListByState(state);
        return regions;
    }
}
